package com.dkt.api.web;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dkt.api.service.UserSrv;
import com.dkt.api.web.dto.Dto;
import com.dkt.api.web.dto.UserDto;
import com.dkt.base.NetConsts;
import com.dkt.base.Resps;
import com.dkt.base.ValidUtil;

/**
 *
 * @author penghy
 * @version 1.0.0
 *
 */
@RestController
@RequestMapping(value = "/user")
public class UserCtrl {

	@Autowired
	private UserSrv userSrv;

	/**
	 * 注册
	 *
	 * @return
	 * @version 2.0
	 */
	@RequestMapping(value = "/reg", method = RequestMethod.POST)
	public Object register(@Validated(Dto.Add.class) UserDto userDto, Errors errors,
			HttpServletResponse response) throws Exception {
		if (errors.hasErrors()) {
			return ValidUtil.errResps(response, errors);
		}

		userSrv.userReg(userDto);
		return new Resps<>(NetConsts.RC_SUCCESS, new String[] {});
	}
}